import { useReactive } from "ahooks";
import { useModel } from "umi";
import compress from "gql-compress";

const useOneStaff = () => {
    const { graphqlFetch } = useModel("global");

    const state = useReactive({
        loading: false,
        staff: {},
    });

    const loadOneStaff = async (osUuid) => {
        state.loading = true;
        let res = await graphqlFetch({
            query,
            variables: {
                osUuid,
            },
        });
        state.staff = res?.a || {};
        state.loading = false;
    };

    return { ...state, loadOneStaff };
};

let query = compress(`query MyQuery($osUuid: UUID!) {
   a: organizationStaffByOsUuid(osUuid: $osUuid) {
      bmSala
      cpInfo
      cpPosi
      daSala
      deInfo
      ecInfo
      fuDays
      isBoss
      omUuid
      opUuid
      osAddr
      osBirt
      osCity
      osDist
      osFrom
      osIdnu
      osName
      osNati
      osPhon
      osPrin
      osRoge
      osStat
      osType
      osUuid
      osZoja
      pyName
      ssBase
      position: organizationPositionByOpUuid {
        opName
      }
    }
}`);

export default useOneStaff;
